<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Sys extends Sys_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->Model('Config_model');
        $this->load->library('form_validation');
        $this->load->library('ajaxMsgModel');
        $this->load->database();
    }

    public function CreateImg()
    {
        $url='http://baidu.com';
        $time=date('YmdHis');
        $outdir=FCPATH.'common/'.$time.'.jpg';;
        $path=FCPATH.'ext/CutyCapt.exe';
        $cmd = "$path --url=$url --out=$outdir";
        $cmd="$path --url=$url --out=$outdir";
        echo( exec($cmd));// exec($cmd);
    }

    public function Config()
    {
        $this->ajaxmsgmodel->Type='1';
        $this->Ajax_Check($this->ajaxmsgmodel);

        $res= $this->Config_model-> Get_Config_FirstRow();
        $data['configModel']=$res;
        $this->load->view('Admin/config/config.html',$data);
    }

    public function Add_Config()
    {
        $this->ajaxmsgmodel->Type='4';
        $this->Ajax_Check($this->ajaxmsgmodel);

        $valiRes= $this->form_validation->run('config_vali');
        if($valiRes)
        {
            //$this->load->view('Admin/config.html');
            $configModel=new $this->Config_model();
            $configModel->title=$this->input->post('title');
            $configModel->description=$this->input->post('description');
            $configModel->keyword=$this->input->post('keyword');
            $configModel->sitelogo=$this->input->post('sitelogo');
            $configModel->statistics=$this->input->post('statistics');
            $configModel->copyright=$this->input->post('copyright');
            $res= $configModel->Inset_Config($configModel);
            if($res>0)
            {
                $this->load->view('Admin/config.html');
                Msg_Redirect('Admin/sys/config','添加成功');
            }
            else
            {
                $this->load->view('Admin/config.html');
            }
        }
        else
        {
            $this->load->view('Admin/config.html');
        }
    }

    public function Edit_Config1()
    {
        $valiRes= $this->form_validation->run('config_vali');
        if($valiRes)
        {
            //$this->load->view('Admin/config.html');
            $configModel=new $this->Config_model();
            $configModel->cid=$this->input->post('cid');
            $configModel->title=$this->input->post('title');
            $configModel->description=$this->input->post('description');
            $configModel->keyword=$this->input->post('keyword');
            $configModel->sitelogo=$this->input->post('sitelogo');
            $configModel->statistics=$this->input->post('statistics');
            $configModel->copyright=$this->input->post('copyright');
            $res= $configModel->Update_Config($configModel);
            if($res>0)
            {
                //p($res);die;
                //$this->load->view('Admin/editconfig.html');
                Msg_Redirect('Admin/sys/config','修改成功');
            }
            else
            {
                //p($res);die;
                //$this->load->view('Admin/editconfig.html');
                Msg_Redirect('Admin/sys/config','修改失败');
            }
        }
        else
        {
            //$this->load->view('Admin/editconfig.html');
            $this->Config();
        }
    }

    public function Edit_Config()
    {
        $this->ajaxmsgmodel->Type='4';
        $this->Ajax_Check($this->ajaxmsgmodel);
        $valiRes= $this->form_validation->run('config_vali');

        $this->load->library('ajaxMsgModel');
        $configModel=new $this->Config_model();
        if($valiRes)
        {
            $configModel->title=$this->input->post('title');
            $configModel->description=$this->input->post('description');
            $configModel->keyword=$this->input->post('keyword');
            $configModel->sitelogo=$this->input->post('sitelogo');
            $configModel->statistics=$this->input->post('statistics');
            $configModel->copyright=$this->input->post('copyright');
            $configModel->icp=$this->input->post('icp');

            if($this->input->post('mark')=="1")//修改
            {
                $configModel->cid=$this->input->post('cid');
                $res= $this->Config_model->Update_Config($configModel);
                if($res>0)
                {
                    $this->ajaxmsgmodel->Msg='修改成功';
                    $this->ajaxmsgmodel->Statu='ok';
                    $this->ajaxmsgmodel->BackUrl=site_url('admin/sys/config');
                }
                else
                {
                    $this->ajaxmsgmodel->Msg='修改失败';
                    $this->ajaxmsgmodel->Statu='err';
                }
            }else{//添加
               // p($configModel);
                $res= $this->Config_model->Inset_Config($configModel);
                if($res>0)
                {
                    $this->ajaxmsgmodel->Msg='添加成功';
                    $this->ajaxmsgmodel->Statu='ok';
                    $this->ajaxmsgmodel->BackUrl=site_url('admin/sys/config');
                }
                else
                {
                    $this->ajaxmsgmodel->Msg='添加失败';
                    $this->ajaxmsgmodel->Statu='err';
                }
            }

        }else{
            $this->ajaxmsgmodel->Msg='服务器验证失败';
            $this->ajaxmsgmodel->Statu='err';
            //$this->ajaxmsgmodel->BackUrl=site_url('admin/sys/config/');
        }
        echo(json_encode($this->ajaxmsgmodel));
    }

    public function DelConfig()
    {
        $this->ajaxmsgmodel->Type='4';
        $this->Ajax_Check($this->ajaxmsgmodel);

        $this->load->library('ajaxMsgModel');
        $cid=$this->uri->segment(4);
        $res=$this->Config_model->DelConfig_ById($cid);
        if($res>0)
        {
            $this->ajaxmsgmodel->Msg='删除成功';
            $this->ajaxmsgmodel->Statu='ok';
            $this->ajaxmsgmodel->BackUrl=site_url('admin/sys/config');
        }
        else
        {
            $this->ajaxmsgmodel->Msg='删除失败';
            $this->ajaxmsgmodel->Statu='err';
        }
        echo(json_encode($this->ajaxmsgmodel));
    }
}
?>